package com.dnui.seven2.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnui.seven2.common.R;
import com.dnui.seven2.entity.Announcement;
import com.dnui.seven2.entity.Article;
import com.dnui.seven2.service.ArticleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/article")
@Slf4j
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 新增文章
     * @param article
     * @return
     */
    @PostMapping("/save")
    public R<String> save(@RequestBody Article article){
        articleService.save(article);
        return R.success("添加文章成功");
    }



    @DeleteMapping("/delete/{articleId}")
    public R<String> delete(@PathVariable Long articleId){
        articleService.deleteArticle(articleId);
        return R.success("删除成功");
    }

    @PutMapping("/update")
    public R<String> update(@RequestBody Article article){
        articleService.updateArticle(article);
        return  R.success("修改成功");
    }


    @GetMapping("/selectAll")
    public R<List<Article>> selectAll(){
        List<Article> articles = articleService.selectAll();
        return  R.success(articles);
    }

    @GetMapping("getById/{ArticleId}")
    public R<Article> getById(@PathVariable Long ArticleId){
        Article article= articleService.getById(ArticleId);
        return  R.success(article);
    }
}
